package com.springsummer.information.green.beans;


public class AnnotationConfigApplicationContext extends GenericApplicationContext{

    private  ClassPathBeanDefinitionReaderScanner beanDefinitionReaderScanner;

    public AnnotationConfigApplicationContext() {
        super();
    }

    public AnnotationConfigApplicationContext(String configLocation) {
        super(configLocation,new DefaultListableBeanFactory());

        try {

            //load(resources);
            //refresh();
            createReader();

            load();
            refresh();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private void load() throws Exception {
        beanDefinitionReaderScanner.loadBeanDefinitions(getConfigLocation());
    }

    protected void createReader() throws Exception {
        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) getBeanFactory();
        this.beanDefinitionReaderScanner = new ClassPathBeanDefinitionReaderScanner(beanDefinitionRegistry);
    }

    @Override
    protected void onRefresh(ConfigurableListableBeanFactory beanFactory) {
        super.onRefresh(beanFactory);
    }

}
